package com.dycx.api.controller.app.food;

import com.dycx.common.RestResponse;
import com.dycx.food.dto.GoodsDTO;
import com.dycx.food.dto.GoodsQueryDTO;
import com.dycx.food.dto.ShoppingCartDTO;
import com.dycx.food.service.GoodsFoodService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/app/food/goods")
@AllArgsConstructor
public class GoodsFoodApiController {

    private GoodsFoodService goodsService;


    /**
     * 分页获取主商品
     **/
    @PostMapping("/getGoodsMainPage")
    public RestResponse<?> getGoodsMainPage(@RequestBody GoodsQueryDTO dto) {
        dto.setIsShelf(true);
        return RestResponse.success(goodsService.getGoodsMainPage(dto));
    }

    /**
     * 获取规格商品
     **/
    @GetMapping("/getGoodsList")
    public RestResponse<?> getGoodsList(Integer mainGoodsId) {
        return RestResponse.success(goodsService.getListByMainGoodsId(mainGoodsId));
    }

    /**
     * 热销商品
     **/
    @GetMapping("/listSalesGoods")
    public RestResponse<?> listSalesGoods(int num) {
        return RestResponse.success(goodsService.listSalesGoods(num));
    }

    /**
     * 公共商品详情
     **/
    @GetMapping("/getGoodsMainDetail")
    public RestResponse<?> getGoodsMainDetail(int mainGoodsId) {
        return RestResponse.success(goodsService.getGoodsMainDetail(mainGoodsId));
    }

    /**
     * 获取商品信息列表
     **/
    @PostMapping("/listGoodsByOrder")
    public RestResponse<?> listGoodsByOrder(@RequestBody List<ShoppingCartDTO> list) {
        return RestResponse.success(goodsService.listGoodsByOrder(list));
    }

    /**
     * 商品搜索
     **/
    @PostMapping("/getSearchGoodsPage")
    public RestResponse<?> getSearchGoodsPage(@RequestBody GoodsDTO goodsDTO) {
        return RestResponse.success(goodsService.getSearchGoodsPage(goodsDTO));
    }
}
